package com.efast.dmom.equipment.service.masterdata.impl;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.efast.dmom.equipment.bean.EquipInterferSpecificDataBean;
import com.efast.dmom.equipment.bean.EquipMainInterferBaseBean;
import com.efast.dmom.equipment.bean.MasterDatePartReportBean;
import com.efast.dmom.equipment.dao.masterdata.EquipMasterDataReportDao;
import com.efast.dmom.equipment.service.masterdata.IEquipMasterDataReportService;
import org.springframework.stereotype.Service;

@Service
public class IEquipMasterDataReportServiceImpl implements IEquipMasterDataReportService {
	
	@Autowired
	private EquipMasterDataReportDao equipMasterDataReportDao;

	@Override
	public Integer[] selectEquipItemsPart(List<MasterDatePartReportBean> list) {
		Integer number = 0;
		Map<String,Integer> map = new LinkedHashMap<String,Integer>();
		Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
		int day = aCalendar.getActualMaximum(Calendar.DATE);
		Map<String,MasterDatePartReportBean> beanMap=new HashMap<>();
		Integer[] s=new Integer[day+1];
		if(list!=null&&list.size()>0){
			for(MasterDatePartReportBean m:list){
				beanMap.put(m.getDay(),m);
			}
		}

		for(int i = 1; i <= day; i++) {
			if(beanMap.get(i+"")!=null) {
				s[i-1] = beanMap.get(i+"").getNumber();
					number+=beanMap.get(i+"").getNumber();
			}else {
				s[i-1] = 0;
				map.put(i+"", 0);
			}
		}
		s[day] = number;
		return s;
	}
	@Override
	public Map<String,Integer[]> selectPartSum() {
		Map<String,Integer[]> map=new HashMap<String,Integer[]>();
		map.put("equipMaintainPart", this.selectEquipItemsPart(equipMasterDataReportDao.selectEquipMaintainItemsPart())); 
		map.put("EquipSparePart",this.selectEquipItemsPart(equipMasterDataReportDao.selectEquipRepirePart()));
		return map;
	}
	@Override
	public Map<String,Object> selectEquipMaintainOrder() {
		Map<String,Object> map=new HashMap<String,Object>();
		List<EquipMainInterferBaseBean> selectEquipMaintainOrder = equipMasterDataReportDao.selectEquipMaintainOrder();
		if(selectEquipMaintainOrder.size()>0&&selectEquipMaintainOrder!=null) {
			map.put("selectEquipMaintainOrder", selectEquipMaintainOrder);
			map.put("maintainNumber", selectEquipMaintainOrder.size());
		}
		
		return map;
	}
	@Override
	public List<EquipInterferSpecificDataBean> selectEquipMaintainOrderDetail(String ordernumber) {
		List<EquipInterferSpecificDataBean> selectEquipMaintainOrderDetail = equipMasterDataReportDao.selectEquipMaintainOrderDetail(ordernumber);
		return selectEquipMaintainOrderDetail;
	}
	@Override
	public Map<String, Object> selectEquipCheckOrder() {
		Map<String,Object> map=new HashMap<String,Object>();
		List<EquipMainInterferBaseBean> selectEquipMaintainOrder = equipMasterDataReportDao.selectEquipCheckOrder();
		if(selectEquipMaintainOrder.size()>0&&selectEquipMaintainOrder!=null) {
			map.put("selectEquipMaintainOrder", selectEquipMaintainOrder);
			map.put("maintainNumber", selectEquipMaintainOrder.size());
		}
		return map;
	}
	@Override
	public List<EquipInterferSpecificDataBean> selectEquipCheckOrderDetail(String ordernumber) {
		List<EquipInterferSpecificDataBean> selectEquipMaintainOrderDetail = equipMasterDataReportDao.selectEquipMaintainOrderDetail(ordernumber);
		if(selectEquipMaintainOrderDetail.size()>0&&selectEquipMaintainOrderDetail!=null) {
			for(EquipInterferSpecificDataBean equipInterferSpecificDataBean:selectEquipMaintainOrderDetail) {
				if(equipInterferSpecificDataBean.getStatus().equals("completed")) {
					equipInterferSpecificDataBean.setStatus(equipInterferSpecificDataBean.getActuralEndTime()+"-completed");
				}
			}
		}
		return selectEquipMaintainOrderDetail;
	}


}
